-- @owner: @nanyang12
-- @date: 2024/10/23
-- @testpoint:执行PREPARE TRANSACTION，分别执行commit，rollback事务

--step1:建表
drop table if exists t_dml_transaction_0115;
create table t_dml_transaction_0115(c_int int);
--step2:开启事务,向表中插入数据,执行prepare transaction
start transaction;
insert into t_dml_transaction_0115 values(1);
prepare transaction 'pxact1';
commit;
--step3:查询表数据
select * from t_dml_transaction_0115;
--step4:查询系统视图
select gid from pg_prepared_xacts;
--step5:执行commit prepare,查询表数据
commit prepared 'pxact1';
select * from t_dml_transaction_0115 ;
--step6:查询系统视图PG_PREPARED_XACTS
select * from pg_prepared_xacts;
--step7:向表中插入数据,执行prepare transaction
begin;
insert into t_dml_transaction_0115 values(2);
prepare transaction 'pxact2';
/
--step8:查询系统视图
select gid from pg_prepared_xacts;
--step9:执行rollback prepare,查询表数据
rollback prepared 'pxact2';
select * from t_dml_transaction_0115 ;
--step10:查询系统视图PG_PREPARED_XACTS
select * from pg_prepared_xacts;
--step11:清理环境
drop table t_dml_transaction_0115 ;